package com.woniuxy.service.dto;

import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@Data
public class UserDetailsDto implements UserDetails {

    private static final long serialVersionUID = 1L;

    private Integer accountId;  //账号id

    private Long id;

    private String username;

    private String phone;

    private String photo;

    private String password;


    private List<MenuDto> menus = new ArrayList<MenuDto>(); //账号对应菜单

    private List<String> roles = new ArrayList<String>();  //账号对应角色

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        List<GrantedAuthority> lists = new ArrayList<GrantedAuthority>();
        for(String role : roles){
            lists.add( () -> role);
        }
        return lists;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
